﻿using System;
using System.Data;
using System.Web.UI.WebControls;

using TempEmployees.BLL.Database;

namespace TempEmployees.Web
{
    public partial class GridViewAssignmentStatus : BaseGridView
    {
        private static readonly int COLUMN_ASSIGNMENT_ID = 1;
        private static readonly int COLUMN_INITIAL_HOURS = 5;
        private static readonly int COLUMN_HOURS_BALANCE = 6;
        private static readonly int COLUMN_INITIAL_BUDGET = 7;
        private static readonly int COLUMN_BALANCE = 8;
        private static readonly int[] budgetColumns = {
            COLUMN_INITIAL_HOURS,
            COLUMN_HOURS_BALANCE,
            COLUMN_INITIAL_BUDGET,
            COLUMN_BALANCE };

        public delegate void dGotoAssignmentDetailes(int assignmentId);

        public dGotoAssignmentDetailes GotoAssignmentDetailes { get; set; }

        public EventHandler OnRowSelected
        {
            set { ViewAssignmentStatus.SelectedIndexChanged += new EventHandler(value); }
        }

        public void SetGridView(Filters filters)
        {
            GridViewDataTable = new DataTable();

            LabelEmptyQueryBudget.Visible = !DbServices.FillAssignmentStatusGridView(GridViewDataTable ,filters);

            SetGridView();
        }

        public static int GetSelectedAssignmentId(GridView gridView)
        {
            int rowIndex = gridView.SelectedIndex;
            GridViewRow row = gridView.Rows[rowIndex];
            string assignmentId = row.Cells[COLUMN_ASSIGNMENT_ID].Text;
            return int.Parse(assignmentId);
        }

        protected void ViewAssignedBudgets_DataBound(object sender, EventArgs e)
        {
            SetBalanceColumns(budgetColumns);   
        }

        protected override GridView GetGridView()
        {
            return ViewAssignmentStatus;
        }

        protected override ObjectDataSource GetDataSource()
        {
            return AssignmentsStatusDataSource;
        }
    }
}